from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2021-04-08 14:10:52.591406
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Thu, 08, Apr, 2021
Time: 14:10:56
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -47.4263
Nobs: 255.000 HQIC: -48.1734
Log likelihood: 3039.75 FPE: 7.25033e-22
AIC: -48.6762 Det(Omega_mle): 5.12869e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.446105 0.126105 3.538 0.000
L1.Burgenland 0.068870 0.062247 1.106 0.269
L1.Kärnten -0.221224 0.054078 -4.091 0.000
L1.Niederösterreich 0.054327 0.137970 0.394 0.694
L1.Oberösterreich 0.224935 0.127816 1.760 0.078
L1.Salzburg 0.271569 0.070226 3.867 0.000
L1.Steiermark 0.145429 0.090004 1.616 0.106
L1.Tirol 0.117092 0.061462 1.905 0.057
L1.Vorarlberg -0.034040 0.056808 -0.599 0.549
L1.Wien -0.060516 0.116463 -0.520 0.603
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.486306 0.149309 3.257 0.001
L1.Burgenland -0.001461 0.073701 -0.020 0.984
L1.Kärnten 0.333744 0.064028 5.212 0.000
L1.Niederösterreich 0.092439 0.163357 0.566 0.571
L1.Oberösterreich -0.064295 0.151335 -0.425 0.671
L1.Salzburg 0.215987 0.083147 2.598 0.009
L1.Steiermark 0.114265 0.106565 1.072 0.284
L1.Tirol 0.141000 0.072771 1.938 0.053
L1.Vorarlberg 0.151853 0.067261 2.258 0.024
L1.Wien -0.457182 0.137893 -3.315 0.001
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.294528 0.062424 4.718 0.000
L1.Burgenland 0.089444 0.030814 2.903 0.004
L1.Kärnten -0.016678 0.026769 -0.623 0.533
L1.Niederösterreich 0.043292 0.068297 0.634 0.526
L1.Oberösterreich 0.285813 0.063271 4.517 0.000
L1.Salzburg 0.022939 0.034763 0.660 0.509
L1.Steiermark 0.023328 0.044554 0.524 0.601
L1.Tirol 0.069059 0.030425 2.270 0.023
L1.Vorarlberg 0.079847 0.028121 2.839 0.005
L1.Wien 0.113596 0.057651 1.970 0.049
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.213903 0.062368 3.430 0.001
L1.Burgenland 0.021156 0.030786 0.687 0.492
L1.Kärnten 0.008059 0.026745 0.301 0.763
L1.Niederösterreich 0.049698 0.068236 0.728 0.466
L1.Oberösterreich 0.401130 0.063214 6.346 0.000
L1.Salzburg 0.083531 0.034732 2.405 0.016
L1.Steiermark 0.135970 0.044513 3.055 0.002
L1.Tirol 0.049024 0.030397 1.613 0.107
L1.Vorarlberg 0.082119 0.028096 2.923 0.003
L1.Wien -0.044638 0.057599 -0.775 0.438
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.511526 0.122165 4.187 0.000
L1.Burgenland 0.085952 0.060302 1.425 0.154
L1.Kärnten 0.009555 0.052388 0.182 0.855
L1.Niederösterreich -0.020942 0.133659 -0.157 0.875
L1.Oberösterreich 0.139227 0.123823 1.124 0.261
L1.Salzburg 0.059178 0.068031 0.870 0.384
L1.Steiermark 0.072288 0.087192 0.829 0.407
L1.Tirol 0.212606 0.059542 3.571 0.000
L1.Vorarlberg 0.033029 0.055033 0.600 0.548
L1.Wien -0.093870 0.112824 -0.832 0.405
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.186182 0.095391 1.952 0.051
L1.Burgenland -0.017220 0.047087 -0.366 0.715
L1.Kärnten -0.013392 0.040907 -0.327 0.743
L1.Niederösterreich -0.037568 0.104367 -0.360 0.719
L1.Oberösterreich 0.407571 0.096686 4.215 0.000
L1.Salzburg 0.021896 0.053122 0.412 0.680
L1.Steiermark -0.001189 0.068083 -0.017 0.986
L1.Tirol 0.155798 0.046493 3.351 0.001
L1.Vorarlberg 0.050540 0.042972 1.176 0.240
L1.Wien 0.252757 0.088098 2.869 0.004
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.242705 0.117667 2.063 0.039
L1.Burgenland 0.019383 0.058082 0.334 0.739
L1.Kärnten -0.065744 0.050459 -1.303 0.193
L1.Niederösterreich -0.062440 0.128738 -0.485 0.628
L1.Oberösterreich 0.020881 0.119264 0.175 0.861
L1.Salzburg 0.079740 0.065527 1.217 0.224
L1.Steiermark 0.336823 0.083982 4.011 0.000
L1.Tirol 0.460947 0.057349 8.038 0.000
L1.Vorarlberg 0.146104 0.053007 2.756 0.006
L1.Wien -0.173908 0.108670 -1.600 0.110
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.154447 0.139651 1.106 0.269
L1.Burgenland 0.043683 0.068934 0.634 0.526
L1.Kärnten -0.072917 0.059887 -1.218 0.223
L1.Niederösterreich 0.162434 0.152791 1.063 0.288
L1.Oberösterreich 0.001027 0.141546 0.007 0.994
L1.Salzburg 0.204751 0.077769 2.633 0.008
L1.Steiermark 0.121693 0.099672 1.221 0.222
L1.Tirol 0.055579 0.068064 0.817 0.414
L1.Vorarlberg 0.097691 0.062911 1.553 0.120
L1.Wien 0.236390 0.128973 1.833 0.067
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.587983 0.075421 7.796 0.000
L1.Burgenland -0.039944 0.037229 -1.073 0.283
L1.Kärnten -0.025382 0.032343 -0.785 0.433
L1.Niederösterreich 0.018647 0.082517 0.226 0.821
L1.Oberösterreich 0.328553 0.076444 4.298 0.000
L1.Salzburg 0.020746 0.042001 0.494 0.621
L1.Steiermark -0.037194 0.053830 -0.691 0.490
L1.Tirol 0.087845 0.036759 2.390 0.017
L1.Vorarlberg 0.111081 0.033976 3.269 0.001
L1.Wien -0.044288 0.069654 -0.636 0.525
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.142555 0.053049 0.162594 0.219494 0.069080 0.082287 0.009375 0.154473
Kärnten 0.142555 1.000000 0.029687 0.203240 0.179161 -0.061112 0.161047 0.026351 0.308313
Niederösterreich 0.053049 0.029687 1.000000 0.240510 0.068057 0.312748 0.140499 0.034811 0.298597
Oberösterreich 0.162594 0.203240 0.240510 1.000000 0.301154 0.262855 0.090503 0.060088 0.137733
Salzburg 0.219494 0.179161 0.068057 0.301154 1.000000 0.151052 0.052315 0.091575 0.000681
Steiermark 0.069080 -0.061112 0.312748 0.262855 0.151052 1.000000 0.107073 0.101741 -0.111928
Tirol 0.082287 0.161047 0.140499 0.090503 0.052315 0.107073 1.000000 0.163613 0.147201
Vorarlberg 0.009375 0.026351 0.034811 0.060088 0.091575 0.101741 0.163613 1.000000 0.003205
Wien 0.154473 0.308313 0.298597 0.137733 0.000681 -0.111928 0.147201 0.003205 1.000000